package com.autumn.scheduler.bean;

import java.util.Map;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.type.AnnotationMetadata;

import com.autumn.mq.rabbit.register.AutumnRabbitBeanDefinitionRegisterManager;
import com.autumn.mq.rabbit.register.AutumnRabbitConnectionInfo;
import com.autumn.scheduler.queue.QueueContext;
import com.autumn.spring.boot.bean.AbstractImportBeanDefinitionRegister;
import com.autumn.spring.boot.properties.PropertiesConstant;

/**
 * 调度队列定义注册
 * 
 * @author 老码农
 *
 *         2018-07-05 16:26:27
 */
public class SchedulerMqDefinitionRegister extends AbstractImportBeanDefinitionRegister {

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		// 本地不需要配置，根据配置中心自动返回
		AutumnRabbitConnectionInfo info = new AutumnRabbitConnectionInfo();
		info.setBeanPrefix(QueueContext.QUEUE_BEAN_PREFIX);
		info.setPropertiesPrefix(PropertiesConstant.AUTUMN_MESSAGE_RABBIT_MQ_PROPERTIES_PREFIX);

		AutumnRabbitBeanDefinitionRegisterManager regManager = new AutumnRabbitBeanDefinitionRegisterManager(
				this.getEnvironment(), this.getResourceLoader(), registry);
		
		Map<String, Object> map = regManager.getRegisterManager()
				.getEnvironmentPropertiesMap(info.getPropertiesPrefix());
		
		info.setProperties(map);		
		regManager.registerConnectionFactory(info);
	}

}
